package lab01;

public class Test05 {

    public static void main(String[] args) {

        int sum = 0;

        printFor(sum);
        printWhile(sum);
        printDoWhile(sum);
    }

    public static void printFor(int sum) {

        for (int i = 1;i <= 100;i++) {
            sum += i;
        }

        System.out.println("用for语句求1到100的和：");
        System.out.println("sum = " + sum);
    }

    public static void printWhile(int sum) {

        int i = 1;

        while (i <= 100) {
            sum += i;
            i++;
        }

        System.out.println("用while语句求1到100的和：");
        System.out.println("sum = " + sum);
    }

    public static void printDoWhile(int sum) {

        int i = 1;

        do {
            sum += i;
            i++;
        } while (i <= 100);

        System.out.println("用do……while语句求1到100的和：");
        System.out.println("sum = " + sum);
    }
}
